﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using JWXH.XH.pages.listview.viewmodel;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace JWXH.XH.pages.listview
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class ListViewTest1 : ContentPage
    {
        public ListViewTest1Model ViewModel { get; set; } = new ListViewTest1Model();
        public ListViewTest1()
        {
            InitializeComponent();
            BindingContext = ViewModel;
            ViewModel.Title = "翻墙爱好者";
            ViewModel.ListItems = new List<FlyWall>()
            {
                new FlyWall()
                {
                    Name = "shadowsocks",
                    Desc = "first fly wall tool",
                    Img = "http://jwell-xh.oss-cn-shenzhen.aliyuncs.com/20180226093621_ac3530503ab64bc0a30546b7b98af417_.jpg?x-oss-process=image/resize,h_224,w_280"
                },new FlyWall()
                {
                    Name = "shadowsocksR",
                    Desc = "more speed fly wall tools",
                    Img = "http://www.52hhx.com/imgs/header_21ebbfd7.png"
                },new FlyWall()
                {
                    Name = "v2ray",
                    Desc = "more safe and speed",
                    Img = "http://jwell-xh.oss-cn-shenzhen.aliyuncs.com/20180223135656_f70a80b8e4694dc889b7ec0a383e788d_.jpg?x-oss-process=image/resize,h_224,w_280"
                }
            };

            ObservableCollection<FlyWall> list = new ObservableCollection<FlyWall>(ViewModel.ListItems);
            ListViewDatas3.ItemsSource = ListViewDatas2.ItemsSource = ListViewDatas1.ItemsSource = list;
        }

        // 修改第一项的
        private void BtnChangeFiled_OnClicked(object sender, EventArgs e)
        {
            if (ViewModel.ListItems?.Count > 0) ViewModel.ListItems[0].Name = "第一项被修改";

        }

        private void ListViewDatas1_OnItemTapped(object sender, ItemTappedEventArgs e)
        {
            (sender as ListView).SelectedItem = null;
        }

        private void BtnListViewGroup_OnClicked(object sender, EventArgs e)
        {
            this.Navigation.PushAsync(new ListViewGroup());
        }

        private void BtnAddData_OnClicked(object sender, EventArgs e)
        {
            ViewModel.ListItems.AddRange(new List<FlyWall>()
            {
                new FlyWall()
                {
                    Name = "shadowsocks",
                    Desc = "first fly wall tool",
                    Img = "http://jwell-xh.oss-cn-shenzhen.aliyuncs.com/20180226093621_ac3530503ab64bc0a30546b7b98af417_.jpg?x-oss-process=image/resize,h_224,w_280"
                },new FlyWall()
                {
                    Name = "shadowsocksR",
                    Desc = "more speed fly wall tools",
                    Img = "http://www.52hhx.com/imgs/header_21ebbfd7.png"
                },new FlyWall()
                {
                    Name = "v2ray",
                    Desc = "more safe and speed",
                    Img = "http://jwell-xh.oss-cn-shenzhen.aliyuncs.com/20180223135656_f70a80b8e4694dc889b7ec0a383e788d_.jpg?x-oss-process=image/resize,h_224,w_280"
                }
            });


            (ListViewDatas3.ItemsSource as ObservableCollection<FlyWall>).Add(new FlyWall()
            {
                Name = "shadowsock111123s",
                Desc = "first fly wall tool",
                Img = "http://jwell-xh.oss-cn-shenzhen.aliyuncs.com/20180226093621_ac3530503ab64bc0a30546b7b98af417_.jpg?x-oss-process=image/resize,h_224,w_280"
            });
        }

        private void BtnGoPage_OnClicked(object sender, EventArgs e)
        {
            this.Navigation.PushAsync(new ListViewPages());
        }

        private void RefreshPage_Clicked(object sender, System.EventArgs e)
        {
            this.Navigation.PushAsync(new FreshPageByListview());
        }
    }
}